import 'package:flutter/material.dart';
import 'package:yp/config/style.dart';
import 'package:yp/widgets/button_widget.dart';

class TaskItem extends StatefulWidget {
  final String icon;
  final String name;
  final String btn;
  final Function btnClick;
  final String subName;
  final Widget tips;
  final bool finish;
  const TaskItem(this.icon, this.name, this.btn, this.btnClick,
      {Key key,
      this.subName,
      this.tips = const SizedBox(),
      this.finish = false})
      : super(key: key);

  @override
  _TaskItemState createState() => _TaskItemState();
}

class _TaskItemState extends State<TaskItem> {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 16, top: 12),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Container(
            width: 40,
            height: 40,
            child: Image.asset(widget.icon),
            decoration: BoxDecoration(
                color: EsColors.Money,
                borderRadius: BorderRadius.all(Radius.circular(20))),
          ),
          SizedBox(width: 12),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Text(widget.name ?? '',
                        style: TextStyle(
                            fontSize: EsSizes.MD,
                            color: EsColors.Title,
                            fontWeight: EsFontWeights.Normal)),
                    widget.tips
                  ],
                ),
                Visibility(
                  visible: widget.subName?.isNotEmpty ?? false,
                  child: Text(widget.subName ?? '',
                      style: TextStyle(
                          fontSize: EsSizes.XS,
                          color: EsColors.Money,
                          fontWeight: EsFontWeights.Normal)),
                ),
              ],
            ),
          ),
          Row(
            children: [
              Visibility(
                visible: !(widget.finish ?? true),
                child: EsOutLineButton(
                  widget.btn,
                  bgColor: EsColors.White,
                  textColor: EsColors.Money,
                  borderColor: EsColors.Money,
                  onTap: widget.btnClick,
                  padding: EdgeInsets.symmetric(vertical: 4, horizontal: 14),
                ),
              ),
              Visibility(
                visible: widget.finish ?? false,
                child: Image.asset(
                  'assets/images/task_done.png',
                  height: 60,
                  width: 60,
                ),
              )
            ],
          ),
          SizedBox(width: 12)
        ],
      ),
    );
  }
}
